package demo1enum;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: xiaotutu
 * Date: 2025-01-16
 * Time: 17:29
 */
public class Test {

    public static void reflectPrivateConstructor() {
        try {
            Class<?> c1 = Class.forName("demo1enum.TestEnum");
            Constructor<?> constructor =  c1.getDeclaredConstructor(String.class,int.class,double.class, String.class);
            constructor.setAccessible(true);

            TestEnum testEnum =
                    (TestEnum)constructor.newInstance("123",8,9.9,"青色");

            System.out.println(testEnum);

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        reflectPrivateConstructor();
    }
}
